// main仓库
// 子reducer
const mainState = { current: 50 }

const ACTIONS = {
  changeCurrent: Symbol(),
}

//  action creator作用是：让组件和仓库通信更优雅
export const MainActions = {
  changeCurrent: (num: number) => ({ type: ACTIONS.changeCurrent, payload: num }),
}

const mainReducer = function (state = mainState, action: any) {
  const { type, payload } = action
  switch (type) {
    case ACTIONS.changeCurrent:
      return { ...state, current: payload }
    default:
      return state
  }
}

export default mainReducer
